#!/bin/bash
proc() {
    echo -e "\033[42;32m > $@ \033[0m" >&2
    local command=("$@")
    if "${command[@]}"; then
        echo -e "\033[42;32m SUCCEED \033[0m \n" >&2
    else
        echo -e "\033[41;32m FAILED \033[0m \n" >&2
        exit 1
    fi
}

targetIP="192.168.3.53"
v3spath=/home/raii/KzLab/v3s
kernelpath=${v3spath}/linux-zero-5.2.y
ubootpath=${v3spath}/u-boot
mkimgpath=${v3spath}/mkimg
targetFs1=/fs1

# 编译
proc "./buildKernel.sh"

# 拷贝输出件至当前目录
proc cp ${kernelpath}/arch/arm/boot/zImage .
proc cp ${kernelpath}/arch/arm/boot/dts/sun8i-v3s-licheepi-zero.dtb .

proc ssh -t root@${targetIP} "mount /dev/mmcblk0p1 /fs1; echo "mount done""
proc scp zImage root@${targetIP}:${targetFs1}
proc scp sun8i-v3s-licheepi-zero.dtb root@${targetIP}:${targetFs1}
proc ssh -t root@${targetIP} "reboot"
